package reg
{
	import flash.display.Sprite;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.FileFilter;
	import flash.net.FileReference;
	
	import util.SimpleButton;
	
	public class LangPackReg extends Sprite
	{
		private var fr:FileReference;
		
		public function LangPackReg()
		{
			this.stage.scaleMode = StageScaleMode.NO_SCALE;
			this.stage.align = StageAlign.TOP_LEFT;
			var button:SimpleButton = new SimpleButton("请选择Txt文件");
			button.x = 100;
			button.y = 100;
			this.addChild(button);
			button.addEventListener(MouseEvent.CLICK,onButtonClick);
		}
		
		public function onButtonClick(event:MouseEvent):void {
			var ff:FileFilter = new FileFilter(".txt","*.txt");
			fr = new FileReference();
			fr.addEventListener(Event.SELECT,onSelect);
			fr.browse([ff]);
		}
		
		public function onSelect(event:Event):void {
			fr.removeEventListener(Event.SELECT,onSelect);
			fr.addEventListener(Event.COMPLETE,onLoadComplete);
			fr.load();
		}
		
		public function onLoadComplete(event:Event):void {
			fr.removeEventListener(Event.COMPLETE,onLoadComplete);
			var targetContent:String = "";
			var content:String = fr.data.readUTFBytes(fr.data.bytesAvailable);
			var tmpReg:RegExp = new RegExp("\\[.*\".*\\]", "g");
			var arrMatch:Array = content.match(tmpReg);
			for each(var el:String in arrMatch) {
				trace(el);
			}
		}
	}
}